package com.zzb.myshowme.presenter.impl;

import com.zzb.myshowme.bean.UserInfo;
import com.zzb.myshowme.model.PhoneLoginModel;
import com.zzb.myshowme.model.impl.PhoneLoginModelImpl;
import com.zzb.myshowme.presenter.PhoneLoginPresenter;
import com.zzb.myshowme.view.IView.PhoneLoginView;

/**
 * Created by Administrator on 2016/10/13.
 */
public class PhoneLoginPresenterImpl implements PhoneLoginPresenter, PhoneLoginModel.OnLoginFinishedListener {

    private PhoneLoginView mPhoneLoginView;
    private PhoneLoginModel mPhoneLoginModel;

    public PhoneLoginPresenterImpl(PhoneLoginView mPhoneLoginView) {
        this.mPhoneLoginView = mPhoneLoginView;
        this.mPhoneLoginModel = new PhoneLoginModelImpl();
    }

    @Override
    public void login(String username, String password) {
        if (username.equals("") || password.equals("")) {
            mPhoneLoginView.showToastError("手机号或密码不能为空");
            return;
        }
        mPhoneLoginView.showProgress();
        mPhoneLoginModel.login(username, password, this);
    }

    @Override
    public void onSuccess(UserInfo user) {
        if (mPhoneLoginView != null) {
            mPhoneLoginView.hideProgress();
            mPhoneLoginView.navigateToHome(user);
        }
    }

    @Override
    public void onFailure(String error) {
        if (mPhoneLoginView != null) {
            mPhoneLoginView.hideProgress();
            mPhoneLoginView.showToastError(error);
        }
    }
}
